#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

#define EXE "child.out"

int create_process(char* path, char* args[])
{
    int ret = fork();
    if (ret == 0) {
        execve(path, args, NULL);
    }

    return ret;
}

void zero_str(char* s)
{
    while (s && *s) *s++ = 0;
}

int main()
{
    char path[] = EXE;
    char arg1[] = "hello";
    char arg2[] = "world";

    char* args[] = {path, arg1, arg2, NULL};

    printf("pid = %d begin\n", getpid());
    printf("pid = %d, child = %d\n", getpid(), create_process(EXE, args));

    zero_str(path);
    zero_str(arg1);
    zero_str(arg2);

    printf("pid = %d, path = %s\n", getpid(), path);
    printf("pid = %d, arg1 = %s\n", getpid(), arg1);
    printf("pid = %d, arg2 = %s\n", getpid(), arg2);
    
    printf("pid = %d end", getpid());

    return 0;
}
